package cn.wolfcode.mq;

import cn.wolfcode.service.IOrderInfoService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by wolfcode-lanxw
 */
@Component
@RocketMQMessageListener(consumerGroup = "OrderTimeOutMQListener", topic = MQConstant.ORDER_PAY_TIMEOUT_TOPIC)
public class OrderTimeOutMQListener implements RocketMQListener<OrderMQResult> {
    @Autowired
    private IOrderInfoService orderInfoService;

    @Override
    public void onMessage(OrderMQResult param) {
        try {
            System.out.println("收到订单支付超时消息......");
            Integer time = param.getTime();
            Long seckillId = param.getSeckillId();
            String orderNo = param.getOrderNo();
            // 判断订单的状态.
            orderInfoService.cancelOrder(time, seckillId, orderNo);
        } catch (Exception e) {
            e.printStackTrace();
            //超时取消订单的时候没有更新到订单状态(可能刚好支付和超时取消碰在一块),通过mq发送消息到某个队列，通知客服人员检查订单状态(人工处理)
        }
    }
}
